﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace SlaktDataReader
{
    /// <summary>
    /// Interaction logic for winLocation.xaml
    /// </summary>
    public partial class winLocation : Window, INotifyPropertyChanged
    {
        public Location loc { get; set; }

        public bool IsLevel1
        {
            get { return (loc != null ? ((loc.Level == 1) ? true : false) : true); }
            set { loc.Level = 1; _NotifyLevel(); }
        }
        public bool IsLevel2
        {
            get { return (loc != null ? ((loc.Level == 2) ? true : false) : false); }
            set { loc.Level = 2; _NotifyLevel(); }
        }
        public bool IsLevel3
        {
            get { return (loc != null ? ((loc.Level == 3) ? true : false) : false); }
            set { loc.Level = 3; _NotifyLevel(); }
        }
        public bool IsLevel4
        {
            get { return (loc != null ? ((loc.Level == 4) ? true : false) : false); }
            set { loc.Level = 4; _NotifyLevel(); }
        }

        public ObservableCollection<Location> Counties
        {
            get
            {
                if (Globals.Locations != null)
                {
                    return new ObservableCollection<Location>((from v in Globals.Locations where v.Level == 1 select v).ToList());
                }
                return null;
            }
        }

        public Visibility ParentVisible
        {
            get
            {
                if (loc != null)
                {
                    return (loc.Level == 1) ? Visibility.Collapsed : Visibility.Visible;
                }
                return Visibility.Collapsed;
            }
        }

        public GridLength ParentLocationHeight
        {
            get
            {
                return (ParentVisible == System.Windows.Visibility.Visible ? new GridLength(50.0) : new GridLength(0));
            }
        }

        public winLocation()
        {
            InitializeComponent();

            loc = new Location();
            loc.Level = 1;
            _NotifyLevel();
        }

        private void _NotifyLevel()
        {
            Notify("IsLevel1");
            Notify("IsLevel2");
            Notify("IsLevel3");
            Notify("IsLevel4");
            Notify("ParentVisible");
            Notify("ParentLocationHeight");
        }

        private void Notify(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;

        private void bOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Notify("loc");
            _NotifyLevel();
        }
    }
}
